#include "../include/TimeValue.h"
#include "../include/NDK.h"

#include <cassert>
#include <pthread.h>
#include <iostream>

int main ()
{
    timeval tval;
    gettimeofday (&tval, 0);
    TimeValue tv;
    assert (tv == TimeValue::zero);
    assert (tv.sec () == 0);
    assert (tv.msec () == 0);
    assert (tv.usec () == 0);
    
    tv.set (tval);
    assert (tv.sec () == tval.tv_sec);
    assert (tv.usec () == tval.tv_usec);
    assert (tv.sec () == time(NULL));

    std::cout << "sec:" << tv.sec () << " msec:" 
	<< tv.msec () << " usec:" << tv.usec () << std::endl;

    TimeValue tv_copy(tv);
    assert (tv == tv_copy);

    tv_copy += tv;

    assert (tv_copy == (tv + tv));
    tv_copy.set (2, 0);
    timeval tt = tv_copy;
    TimeValue tv_befor(time(NULL));
    select (0, 0, 0, 0, &tt);
    TimeValue tv_after(time(NULL));
    assert ((tv_after - tv_befor) == TimeValue(2));

    TimeValue tv_zero (1, -1000000);
    assert (tv_zero == TimeValue::zero);
}
